<?php
namespace Home\Controller;
use Think\Controller;
class UserController extends Controller
{
public function userLogin(){
    $username=$_GET['username'];
    $user_password=$_GET['user_password'];
    $userModel=M('users');
    $user=$userModel->where("username='$username' and user_password='$user_password'" )->field('user_id')->select();
    if($user==null)
    {
         echo  json_encode(failed);
    }
    else
    {
        $_SESSION['user_id']=$map['user_id'];
        $_SESSION['username']=$map["username"];
        echo  json_encode(successful);
    }
    echo json_encode($user);
  }




// Public function userReg(){
//     $data['user_id']=$_note['user_id'];
//     $data['username']=$_note['username'];
//     $data['user_password']=$_note['user_password'];
//     $data['user_tel']=$_note['user_tel'];   
//     $data['createtime'] =  date("Y-m-d H:i:s"); 
//     $usermodel=M('users');                                       
//     $user=$usermodel->add($data);
//     if(false !==$user){          
//          $this->ajaxReturn(SUCCESS,'JSON');
//     }else{
//         //$this->false;
//          $this->ajaxReturn($FALSE,'JSON');
//     }              
// }

   Public function userReg(){
    $username = $_GET['username'];
    $data['username']=$username;
    $data['user_password']=$_GET['user_password'];
    $data['user_tel']=$_GET['user_tel'];
    $userModel = M('users');
    $user=$userModel->where("username='$username'")->select();
    if(empty($user)){
      $result=$userModel->add($data);
      if($result=0){
        $succes['succes']=1;
        echo json_encode($succes);
      }
      else
      {
        $succes['succes']=0;
        echo json_encode($succes);
      }
    }

    else{
      $succes['succes']=-1;
        echo json_encode($succes);
    }
   }



public function upload()
    {
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize = 3145728;// 设置附件上传大小
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath = './Public/Uploads/logo/'; // 设置附件上传根目录
        //$upload->savePath  =     ''; // 设置附件上传（子）目录
        $upload->autoSub = false;
        $info = $upload->upload();  // 上传文件
       
        if (!$info) {
            $this->error($upload->getError());
        } else {
            //$this->success('上传成功！');
            return $info;
        }
    }





    //   public function getmyInfo(){
    //   $user_id=$_GET['user_id'];
    //   $usermodel=M('users');
    //   $user=$usermodel->find($user_id); 
    //   $this->user=$user;
    //   exit(json_encode($user));
    // } 
 public function getmyInfo(){
      $user_id=$_GET['user_id'];
      $usermodel=M('users');
      $user=$usermodel->find($user_id); 
      $this->user=$user;
      exit(json_encode($user));
    } 
/*9.查看自己的发帖信息*/
     public function userNotelist(){   
     $user_id=$_GET['user_id'];
     $notemodel=M('note');
     $note=$notemodel->table('note p,users u,club c')->where("p.user_id=$user_id and p.club_id=c.club_id and p.user_id=u.user_id")->field('p.*,u.user_name,c.club_name')->select();
        //调用视图层显示数据
     $this->note=$note;
     exit(json_encode($note));
    }
    /*修改个人信息*/
     public function editUser(){
      $user_id=$_GET['user_id'];
      $usermodel=M('users');
      $user=$usermodel->find($user_id); 
      $this->user=$user;
      exit(json_encode($user));
    }
    
  Public function updateUserById(){
    $data['user_id']=$_note['user_id'];
    $data['username']=$_note['username'];
    $data['user_password']=$_note['user_password'];
    $data['user_tel']=$_note['user_tel'];      
    $data['createtime'] =  date("Y-m-d H:i:s"); 
    $usermodel=M('users');                                          
    $user=$usermodel->save($data);
    if(false !==$user){   
    $this->ajaxReturn(SUCCESS,'JSON');
    }else{
        //$this->false;
         $this->ajaxReturn($FALSE,'JSON');
    }
    
    
    }
  }
?>